package com.cykj.page02.service.impl;

import com.cykj.page02.dao.IUserDao;
import com.cykj.page02.dao.factory.DaoFactory;
import com.cykj.page02.dto.ResponseDTO;
import com.cykj.page02.entity.StudentDO;
import com.cykj.page02.service.IUserService;

/**
 * @BelongsProject: hand-tomcat
 * @BelongsPackage: com.cykj.page01.service.impl
 * @Author: 阿隆
 * @CreateTime: 2025-11-01 11:38
 * @Description: TODO
 * @Version: 1.0
 */
public class UserServiceImpl implements IUserService {

    private IUserDao userDao = DaoFactory.getUserDao();

    //2.自己创建一个实例 (单例设计模式  懒汉模式)
    private static UserServiceImpl userService;

    //1.私有构造方法
    private UserServiceImpl() {

    }

    //3.提供公有静态的访问方法
    public static UserServiceImpl getInstance() {
        if (userService == null) {
            userService = new UserServiceImpl();
        }
        return userService;
    }




/*    //2.自己创建一个实例  (单例设计模式 饿汉模式)
    private static UserServiceImpl userService = new UserServiceImpl();

    //1.私有构造方法
    private UserServiceImpl() {

    }

    //3.提供公有静态的访问方法
    public static UserServiceImpl getInstance() {
        return userService;
    }*/

    @Override
    public ResponseDTO login(String account, String password) {

        StudentDO studentDO = userDao.login(account, password);

        if (studentDO != null) {
            return ResponseDTO.success(studentDO);
        }

        return ResponseDTO.fail();
    }

    @Override
    public ResponseDTO insertStudent(Integer stuId, String account, String password) {
        Integer res = userDao.insertStudent(stuId, account, password);
        return ResponseDTO.effectResult(res);

    }
}
